package com.fellansoft.moviescollection.data;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.net.Uri;
import android.widget.ImageView;
import com.fellansoft.moviescollection.R;
import com.fellansoft.moviescollection.gui.GuiUtilities;
import com.fellansoft.moviescollection.utils.ApplicationVariables;

import java.io.IOException;


/**
 * Created by IntelliJ IDEA.
 * User: Edy
 * Date: 12.05.2012
 * Time: 16:16
 * To change this template use File | Settings | File Templates.
 */
public class CoverFlowFolder extends CoverFlowElement {


    /**
    *
     */
    public CoverFlowFolder(Context ctx, Uri uri1, Uri uri2, Uri uri3, Uri uri4) throws IOException {
        int folderThumbD, movieThumbD, marginD;
        folderThumbD = 4 * ApplicationVariables.getDisplayHeight() / 15;
        movieThumbD = ApplicationVariables.getDisplayHeight()/11;
        marginD = ApplicationVariables.getDisplayHeight()/44;

        Bitmap bm = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.f);

        int width = bm.getWidth();
        int height = bm.getHeight();
        float scaleWidth = ((float) folderThumbD) / width;
        float scaleHeight = ((float) folderThumbD) / height;
        // create a matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bit map
        matrix.postScale(scaleWidth, scaleHeight);
        // recreate the new Bitmap
        Bitmap folderBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
        Canvas canvas = new Canvas(folderBitmap);

        ImageView imageView = null;

        Bitmap thumb1=null,thumb2=null,thumb3=null,thumb4=null;
        if (uri1!=null)
            thumb1= GuiUtilities.getSquareThumbnailFromUri(uri1, movieThumbD);
        if (uri2!=null)
            thumb2 = GuiUtilities.getSquareThumbnailFromUri(uri2, movieThumbD);
        if (uri3!=null)
            thumb3 = GuiUtilities.getSquareThumbnailFromUri(uri3, movieThumbD);
        if (uri4!=null)
            thumb4 = GuiUtilities.getSquareThumbnailFromUri(uri4, movieThumbD);

        if (thumb1 != null)
            canvas.drawBitmap(thumb1, (int)(1.5*marginD), (int)(2.5*marginD), null);
        if (thumb2 != null)
            canvas.drawBitmap(thumb2, folderThumbD - (int)(1.5*marginD) - movieThumbD, (int)(2.5*marginD), null);
        if (thumb3 != null)
            canvas.drawBitmap(thumb3, (int)(1.5*marginD), folderThumbD - movieThumbD - marginD, null);
        if (thumb4 != null)
            canvas.drawBitmap(thumb4, folderThumbD - movieThumbD - (int)(1.5*marginD), folderThumbD - movieThumbD - marginD, null);

        mBitmap = folderBitmap;
    }
}
